﻿using CTP.CRM.Core.SharedModel.Enums;
using CTP.CRM.Core.SharedModel.Pub;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace CTP.CRM.Application.Dtos.OAuth
{
    public class GenerateTokenInput
    {
        public TokenOrigin TokenOrigin { get; protected set; }

        public int Id { get; set; }
        public string Name { get; set; }

        public string EnName { get; set; }

        public string TelPhone { get; set; }

        public int? EmployeeId { get; set; }

        public string Account { get; set; }

        /// <summary>
        /// Ensure called last
        /// </summary>
        /// <returns></returns>
        public virtual List<Claim> MapUserToClaims()
        {
            var claims = new List<Claim>() { new Claim(UserCenterClaimTypes.TokenOrigin, this.TokenOrigin.ToString()) };
            claims.Add(new Claim(UserCenterClaimTypes.UserId, this.Id == 0 ? "" : this.Id.ToString()));
            claims.Add(new Claim(UserCenterClaimTypes.EmpId, this.EmployeeId is null ? "" : this.EmployeeId.ToString()));
            return claims;
        }

        public virtual GenerateTokenInput AssignTokenOrigin(TokenOrigin tokenOrigin)
        {
            this.TokenOrigin = tokenOrigin;
            return this;
        }

    }
}
